﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using MongoDB.Driver;

namespace DatabaseRepository
{
    public class MongoConnectionHelper<T> where T : class
    {
        public MongoCollection<T> Collection { get; set; }

        public MongoConnectionHelper() { 
            var connecitonString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
            var url = new MongoUrlBuilder(connecitonString);
            var client = new MongoClient(connecitonString);
            var server = client.GetServer();
            var database = server.GetDatabase(url.DatabaseName);

            Collection = database.GetCollection<T>(typeof(T).Name.ToLower());
        }
    }
}
